<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'routing-form',
	'enableAjaxValidation'=>false,
)); 

Yii::app()->clientScript->registerScript('admin', "
$(document).ready(function(){
                var flag = $('#flag').val();
                 $('#Routing_tag').append('<option value=0>'+'请您选择'+'</option>');
                if(flag == ''){
                    $('#Routing_tag option[value=0]').attr('selected',true);
                }
                var options = $('#Routing_tag option:selected').val();
		if(options==1){
                    $('#Routing_vpnid').show();
                    $('label:eq(3)').show()
		}else{
                    $('#Routing_vpnid').append('<option value=0>'+''+'</option>');
                    $('#Routing_vpnid option[value=0]').attr('selected',true);
                    $('#Routing_vpnid').hide();
                    $('label:eq(3)').hide()
                }
		$('#Routing_tag').change(function(){
			$('#Routing_vpnid').hide();
			$('label:eq(3)').hide();
                        var tag = $('#Routing_vpnid option[value=0]').val();
                        if(tag != 0){
                        $('#Routing_vpnid').append('<option value=0>'+''+'</option>');
                        $('#Routing_vpnid option[value=0]').attr('selected',true);
                        }
			var options = $('#Routing_tag option:selected').val();
			if(options==1){
                                $('#Routing_vpnid option[value=0]').remove();
				$('#Routing_vpnid').show();
				$('label:eq(3)').show()
		}
	})
})
");
?>
	<p class="note"><?php echo Yii::t('base','Fields with <span class="required">*</span> are required.');?></p>

	<?php echo $form->errorSummary($model); ?>
	<input name="Routing[user_id]" id="Routing_user_id" type="hidden" value=<?php echo yii::app()->user->id;?>>
	<div class="row">
		<?php echo $form->hiddenField($model,'routing_id'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'IP'); ?>
		<?php echo $form->textField($model,'IP',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'IP'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'maskbit'); ?>
		<?php echo $form->textField($model,'maskbit',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'maskbit'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'tag');?>
		<?php
                  if($model->routing_id != ""){
                    $result = Routing::model()->find('routing_id='.$model->routing_id);
                 }
		$level=yii::app()->user->level;
		if($level==1){ 
			echo $form->dropDownList($model,'tag',array('1'=>Yii::t('base','Routing By VPN'),'2'=>Yii::t('base','Access Denied')),array('options' => array($result['tag']=>array('selected'=>true))));
		}else{
			$rs = Routing::model()->checkVPN();
		//	print_r($rs);
			if($rs==""){
				echo $form->dropDownList($model,'tag',array('2'=>Yii::t('base','Access Denied'),'3'=>Yii::t('base','Routing By Local')),array('options' => array($result['tag']=>array('selected'=>true))));
			}else{
				echo $form->dropDownList($model,'tag',array('1'=>Yii::t('base','Routing By VPN'),'2'=>Yii::t('base','Access Denied'),'3'=>Yii::t('base','Routing By Local')),array('options' => array($result['tag']=>array('selected'=>true))));
			}
		} ?>
		<?php echo $form->error($model,'tag'); ?>
          <input name="flag" id="flag" type="hidden" value="<?php echo $result['tag']; ?>" />
	</div>
	<?php $id = yii::app()->user->id;
		$rs=User::model()->findByPk($id);
		if($rs->level==1){	
	?>
	<input name="Routing[Ispublic]" id="Routing_Ispublic" type="hidden" value=1>
	<?php }else{?>
	<input name="Routing[Ispublic]" id="Routing_Ispublic" type="hidden" value=0>	
	<?php }?>
	<div class="row">
		<?php echo $form->labelEx($model,'vpnid');?>
 		<?php echo $form->dropDownList($model,'vpnid',Vpnlist::model()->getAllvpnlist(),array('options' => array($result['tag']=>array('selected'=>true))))?>
	</div>
        <div class="row">
		<?php echo $form->labelEx($model,'remark'); ?>
		<?php echo $form->textField($model,'remark',array('maxlength' => 300)); ?>
		<?php echo $form->error($model,'remark'); ?>
	</div>
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('base','Create') : Yii::t('base','Save')); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->